const MyPromise = require('./MyPromise');

function p1 () {
  return new MyPromise(function (resolve, reject) {
    setTimeout(function () {
      resolve('p1')
    }, 2000)
  })
}
function p2 () {
  return new MyPromise(function (resolve, reject) {
    // reject('失败')
    resolve('成功');  
  })
}

p2()
  .then(value => console.log(value))
  .catch(reason => console.log(reason))

MyPromise.all(['a', 'b', p1(), p2(), 'c']).then(result => {
    console.log(result)
    // ["a", "b", "p1", "p2", "c"]
  })

  MyPromise.resolve(100).then(value => console.log(value))
MyPromise.resolve(p1()).then(value => console.log(value))

p2().finally(() => {
    console.log('finallyp2')
    return p1()
  }).then(value => {
    console.log(value)
  }, reason => {
    console.log(reason)
  })